package cz.acies.data.process;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cz.acies.data.dao.DefaultDAO;
import cz.acies.data.persist.ModelObject;
import cz.acies.face.modul.ModulViewer;

public class DefaultProcessor extends AbstractProcessor
{
	@Override
	public String execute(Map<String, Object> params) {
		String data = "";
		String processId = params.containsKey("processId") ? (String) params.get("processId") : "UNKNOW";
		if (processId.equals("getModulPageContent")) {
			Map<String, String> reg = new HashMap<String, String>();
			DefaultDAO dao = new DefaultDAO();
			List<ModelObject> rs = dao.selectAll("gui_modul", ModulViewer.class);
			for (ModelObject obj : rs) {
				reg.put(((ModulViewer) obj).getModulId(), ((ModulViewer) obj).getPageUrl());
			}
			String modulId = (String) params.get("modulId");
			if (reg.containsKey(""+modulId)) {
				String page = reg.get(""+modulId);
				if (page.trim().length() != 0) {
					data = "<iframe scrolling=\"auto\" frameborder=\"0\" src=\"/organizer/pages/" + page + "\" style=\"width:100%;height:100%;\"></iframe>";
				} else {
					data = "<iframe scrolling=\"auto\" frameborder=\"0\" src=\"/organizer/pages/default_modul.jsp?modulId=" + modulId + "\" style=\"width:100%;height:100%;\"></iframe>";
				}
			} else {
				data = "<iframe scrolling=\"auto\" frameborder=\"0\" src=\"/organizer/pages/default_modul.jsp?modulId=" + reg.get(""+modulId) + "\" style=\"width:100%;height:100%;\"></iframe>";
			}
		} else {
			data = "UNKNOW";
		}
		return data;
	}

}
